from unittest.case import skip
import unittest

from Autotests.BaseTest import BaseManservSOAPTestCase, PartnerAndAccountAutoCreation
from Config.RunConfig import RunConfig, Options


@PartnerAndAccountAutoCreation
class GetMethodsTests(BaseManservSOAPTestCase):
    def __init__(self, *args, **kwargs):
        BaseManservSOAPTestCase.__init__(self, *args, **kwargs)
        self._contactPersonName = 'TEST_PERSON'

    def test_GetAccountCustomColumnValues(self):
        columnValues = self.executor.getAccountCustomColumnValues(self.getAccountForCaseInfo().accountInfo)
        targetClass = self.manserv.createObject('mansvc:ArrayOfCustomColumnValue').__class__
        self.assertIsServiceSequence(columnValues, targetClass)

    @unittest.expectedFailure
    def test_GetAccountCustomColumnValuesById(self):
        request= self.manserv.createObject('mansvc:GetAccountCustomColumnValuesByIdRequest')
        request.accountId = self.executor.getAccountCustomColumnValues(
            self.getAccountForCaseInfo().accountInfo).customColumnValues[0].customColumnId
        self.assertIsInstance(self.manserv.call('GetAccountCustomColumnValuesById', request),
                              self.manserv.createObject('mansvc:ArrayOfCustomColumnValue').__class__)

    def test_GetAccountFeatures(self):
        features = self.executor.getAccountFeatures(self._accountForCaseName, self._accountForCasePassword)
        self.assertIsServiceSequence(features, self.manserv.createObject('mansvc:ArrayOfPairOfStrings').__class__)

    def test_GetAccountFeaturesById(self):
        request = self.manserv.createObject('mansvc:GetAccountFeaturesByIdRequest')
        request.accountId = int(self.getAccountForCaseInfo().accountInfo.id)
        self.assertIsServiceSequence(self.manserv.call('GetAccountFeaturesById', request),
                                     self.manserv.createObject('mansvc:ArrayOfPairOfStrings').__class__)

    def test_GetAccountInfo(self):
        self.assertIsNotNone(self.executor.getAccountInfo(self._accountForCaseName, self._accountForCasePassword))

    def test_GetAccountInfoById(self):
        request = self.manserv.createObject('mansvc:GetAccountInfoByIdRequest')
        request.accountId = self.getAccountForCaseInfo().accountInfo.id
        request.includeHomeNodeInfo = True
        self.assertIsNotNone(self.manserv.call('GetAccountInfoById', request))

    def test_GetAdvancedPartnerProperties(self):
        request = self.manserv.createObject('mansvc:GetAdvancedPartnerPropertiesRequest')
        request.partnerId = self.getPartnerForCaseInfo().id
        properties = self.manserv.call('GetAdvancedPartnerProperties', request)
        self.assertIsInstance(properties, self.manserv.createObject('mansvc:AdvancedPartnerPropertiesInfo').__class__)

    def test_GetCloudInfo(self):
        self.assertIsNotNone(self.manserv.GetCloudInfo())

    @skip('this method is in Authentication service what is not used now')
    def test_GetDoubleCheckedLoginStatus(self):
        request = self.manserv.createObject('mansvc:GetDoubleCheckedLoginStatusRequest')
        request.partnerName = self.getPartnerForCaseInfo().name
        request.userName = self.getUserInfo().name

    def test_GetDownloadLinkVerb(self):
        request = self.manserv.createObject('mansvc:GetDownloadLinkVerbRequest')
        request.accountId = self.getAccountForCaseInfo().accountInfo.id
        self.assertIsNotNone(self.manserv.call('GetDownloadLinkVerb', request))

    def test_GetPartnerInfo(self):
        partnerInfo = self.getPartnerForCaseInfo()
        GetPartnerInfo = self.manserv.createObject('mansvc:PartnerInfo').__class__
        self.assertIsInstance(partnerInfo, GetPartnerInfo)

    def test_GetPartnerInfoById(self):
        partnerInfo = self.getPartnerForCaseInfo()
        request = self.manserv.createObject('mansvc:GetPartnerInfoByIdRequest')
        request.id = partnerInfo.id
        self.assertEqual(str(self.manserv.call('GetPartnerInfoById', request)),
                         str(partnerInfo))

    def test_GetPartnerPriceCurrency(self):
        request = self.manserv.createObject('mansvc:GetPartnerPriceCurrencyRequest')
        request.partnerId = self.getPartnerForCaseInfo().id
        self.assertIsNotNone(self.manserv.call('GetPartnerPriceCurrency', request))

    def test_GetPartnerUrl(self):
        urlTypes = {'Undefined' : '',
                    'Logo' : 'http://www.iaso.com/ipad/logo.png',
                    'PresentationDownload' : 'http://www.iasobackup.com/ipad/presentation.zip',
                    'DedicatedQuoteModel' : 'http://www.iasobackup.com/ipad/dsquote.xml',
                    'SharedQuoteModel' : 'http://www.iasobackup.com/ipad/ssquote.xml'}
        for urlType in urlTypes.keys():
            request = self.manserv.createObject('mansvc:GetPartnerUrlRequest')
            request.partnerId = self.getPartnerForCaseInfo().id
            request.urlType = urlType
            self.assertEqual(self.manserv.call('GetPartnerUrl', request), urlTypes[urlType])

    def test_GetRemoteConnectionConfig(self):
        accountInfo = self.getAccountForCaseInfo().accountInfo
        request = self.manserv.createObject('mansvc:GetRemoteConnectionConfigRequest')
        request.account = accountInfo.name
        request.password = accountInfo.password
        remoteConnectionConfig = self.manserv.call('GetRemoteConnectionConfig', request)
        self.assertIsNotNone(remoteConnectionConfig)

    def test_GetRootPartnerName(self):
        rootPartnerName = self.manserv.call('GetRootPartnerName')
        self.assertEqual(rootPartnerName, 'IASO')

    def test_GetServerInfo(self):
        serverInfo = self.manserv.call('GetServerInfo')
        self.assertIsInstance(serverInfo, self.manserv.createObject('mansvc:ServerInfo').__class__)
        self.assertNotEqual(serverInfo.version, '')

    def test_GetUserInfo(self):
        defaultPartnerId = self.manserv.GetPartnerInfo(name=RunConfig().get(Options.Soap.defaultPartner)).id
        userInfo = self.manserv.GetUserInfo(name=RunConfig().get(Options.Soap.defaultUser),
                                            partnerId=defaultPartnerId,
                                            password=RunConfig().get(Options.Soap.defaultPassword))
        self.assertIsInstance(userInfo, self.manserv.createObject('mansvc:UserInfo').__class__)

    def _addContactPerson(self):
        partnerInfo = self.getPartnerForCaseInfo()
        self.executor.addContactPerson(partnerInfo, self._contactPersonName, 'TEST@TEST.ru')
        return self.executor.enumerateContactPersons(partnerInfo).contactPersonInfo[-1]


if __name__ == "__main__":
    unittest.main()
